import ch.cern.Map
import ch.cern.Point
import grails.util.GrailsUtil
import ch.cern.Tag

class BootStrap {

  def init = { servletContext ->

    if ( 'development' == (GrailsUtil.environment) && !Map.count() ) {
      def tags = [rest:new Tag(tag:"restaurant"), hol:new Tag(tag:"holiday"), work:new Tag(tag:"work"), drink:new Tag(tag:"drink")]
      tags.values().each{it.save(failOnError:true)}

      def map = new Map(name:'Dubna', createdOn: new Date()-1500)

      map.addToPoints new Point(title:'University', description:'University', latitude:56.747499, longitude:37.190094,
          createdOn: new Date()-1000, tags: [tags.work])
      map.addToPoints new Point(title:'Pizza Place',description:'Pizza Place', latitude:56.745099, longitude:37.177877,
          createdOn: new Date()-500, tags: [tags.drink, tags.rest])
      map.addToPoints new Point(title:'Dubna Pizza',description:'Dubna Pizza', latitude:56.742463, longitude:37.176955,
          createdOn: new Date(), tags: [tags.drink, tags.rest])
      map.addToPoints new Point(title:'Geneva',description:'Cern', latitude:46.234196, longitude:6.056083,
          createdOn: new Date()-100, tags: [tags.work, tags.hol])

      if (!map.save(fainOnError:true)) {
        map.errors.each { println it }
      }
    }
  }

  def destroy = {
  }
}
